package zhtt;

import org.apache.ibatis.session.SqlSession;
import org.junit.Test;
import zhtt.demo01.Blog;
import zhtt.demo01.Dept;
import zhtt.demo01.User;

/**
 * Created by zhtt on 2017/4/29.
 */
public class UserTest {

    @Test
    public void insertUser(){
        SqlSession sqlSession=null;
        try{
            sqlSession = SessionFactoryUtil.getSqlSessionIntance();
            User user=new User(1,"user2");
            int r=sqlSession.insert("zhtt.demo01.User.insertUser",user);
            System.out.println(user);
            System.out.println(r);
            sqlSession.commit();
        }catch (Exception e){
            e.printStackTrace();
            sqlSession.rollback();
        }finally {
            if(sqlSession!=null)
                sqlSession.close();
        }
    }

    @Test
    public void selectUser(){
        SqlSession sqlSession=null;
        try{
            sqlSession = SessionFactoryUtil.getSqlSessionIntance();
            User user=sqlSession.selectOne("zhtt.demo01.User.get",2);
            System.out.println(user);
        }catch (Exception e){
            e.printStackTrace();
            sqlSession.rollback();
        }finally {
            if(sqlSession!=null)
                sqlSession.close();
        }
    }

    @Test
    public void selectUser1(){
        SqlSession sqlSession=null;
        try{
            sqlSession = SessionFactoryUtil.getSqlSessionIntance();
            User user=sqlSession.selectOne("zhtt.demo01.User.get2",2);
            System.out.println(user);
        }catch (Exception e){
            e.printStackTrace();
            sqlSession.rollback();
        }finally {
            if(sqlSession!=null)
                sqlSession.close();
        }
    }

    @Test
    public void get3(){
        SqlSession sqlSession=null;
        try{
            sqlSession = SessionFactoryUtil.getSqlSessionIntance();
            User user=sqlSession.selectOne("zhtt.demo01.User.get3",2);
            System.out.println(user);
        }catch (Exception e){
            e.printStackTrace();
            sqlSession.rollback();
        }finally {
            if(sqlSession!=null)
                sqlSession.close();
        }
    }

    @Test
    public void get4(){
        SqlSession sqlSession=null;
        try{
            sqlSession = SessionFactoryUtil.getSqlSessionIntance();
            User user=sqlSession.selectOne("zhtt.demo01.User.get4",2);
            System.out.println(user);
        }catch (Exception e){
            e.printStackTrace();
            sqlSession.rollback();
        }finally {
            if(sqlSession!=null)
                sqlSession.close();
        }
    }
}
